package com.imut.lagain.entity;

import com.baomidou.mybatisplus.annotation.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

/**
 * 消息实体类
 */
@TableName("message")
public class Message {
    private static final Logger log = LoggerFactory.getLogger(Message.class);

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    /**
     * 发送者ID
     */
    @NotNull(message = "发送者ID不能为空")
    @TableField("sender_id")
    private Long senderId;
    
    /**
     * 接收者ID
     */
    @NotNull(message = "接收者ID不能为空")
    @TableField("receiver_id")
    private Long receiverId;
    
    /**
     * 消息类型（TEXT-文本，IMAGE-图片，AUDIO-语音，VIDEO-视频，SYSTEM-系统消息）
     */
    @NotBlank(message = "消息类型不能为空")
    @Size(max = 20, message = "消息类型长度不能超过20个字符")
    @TableField("message_type")
    private String messageType;
    
    /**
     * 消息内容
     */
    @NotBlank(message = "消息内容不能为空")
    @Size(max = 2000, message = "消息内容长度不能超过2000个字符")
    @TableField("content")
    private String content;
    
    /**
     * 媒体文件URL（图片、语音、视频等）
     */
    @Size(max = 500, message = "媒体文件URL长度不能超过500个字符")
    @TableField("media_url")
    private String mediaUrl;
    
    /**
     * 消息状态（SENT-已发送，DELIVERED-已送达，READ-已读）
     */
    @TableField("status")
    private String status = "SENT";
    
    /**
     * 是否已读
     */
    @TableField("is_read")
    private Boolean isRead = false;
    
    /**
     * 读取时间
     */
    @TableField("read_time")
    private LocalDateTime readTime;
    
    /**
     * 回复的消息ID
     */
    @TableField("reply_to_id")
    private Long replyToId;
    
    /**
     * 扩展数据（JSON格式）
     */
    @TableField("extra_data")
    private String extraData;
    
    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    
    /**
     * 是否删除
     */
    @TableLogic
    @TableField("is_deleted")
    private Boolean isDeleted = false;

    // 消息类型常量
    public static final String TYPE_TEXT = "TEXT";
    public static final String TYPE_IMAGE = "IMAGE";
    public static final String TYPE_AUDIO = "AUDIO";
    public static final String TYPE_VIDEO = "VIDEO";
    public static final String TYPE_SYSTEM = "SYSTEM";
    
    // 消息状态常量
    public static final String STATUS_SENT = "SENT";
    public static final String STATUS_DELIVERED = "DELIVERED";
    public static final String STATUS_READ = "READ";

    // Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getSenderId() {
        return senderId;
    }

    public void setSenderId(Long senderId) {
        this.senderId = senderId;
    }

    public Long getReceiverId() {
        return receiverId;
    }

    public void setReceiverId(Long receiverId) {
        this.receiverId = receiverId;
    }

    public String getMessageType() {
        return messageType;
    }

    public void setMessageType(String messageType) {
        this.messageType = messageType;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getMediaUrl() {
        return mediaUrl;
    }

    public void setMediaUrl(String mediaUrl) {
        this.mediaUrl = mediaUrl;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Boolean getIsRead() {
        return isRead;
    }

    public void setIsRead(Boolean isRead) {
        this.isRead = isRead;
    }

    public LocalDateTime getReadTime() {
        return readTime;
    }

    public void setReadTime(LocalDateTime readTime) {
        this.readTime = readTime;
    }

    public Long getReplyToId() {
        return replyToId;
    }

    public void setReplyToId(Long replyToId) {
        this.replyToId = replyToId;
    }

    public String getExtraData() {
        return extraData;
    }

    public void setExtraData(String extraData) {
        this.extraData = extraData;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Boolean getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Boolean isDeleted) {
        this.isDeleted = isDeleted;
    }
}